import router from "./router";
import nprogress from "nprogress";
import "nprogress/nprogress.css";
import UseUserStore from "./stores/modules/user";
import pinia from "./stores";
let userStore = UseUserStore(pinia);
//路由白名单
const whiteList = ['/cheackout','/Pay','/paycallback','/member','/member/user','/member/order'];
router.beforeEach((to,form,next)=>{
    nprogress.start();
    if(userStore.token) {
        if(to.path == '/login') {
            next({path:'/'});
            nprogress.done();
        }else {
            next()
        }
      
    }else {
        if(whiteList.includes(to.path)) {
            next('/login')
            nprogress.done();
        }
    }

    
})

router.afterEach((to,form,next)=>{
    nprogress.done();
})